package com.baizhi.springboot.controller;

import com.baizhi.springboot.entity.User;
import com.baizhi.springboot.service.UserService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/updatePassword")
    public Map updatePassword(HttpSession session, Integer password, Integer new1, Integer new2) {
        HashMap<Object, Object> map = new HashMap<>();
        User user = (User) session.getAttribute("user");
        if (user.getPassword().equals(password)&& new1==new2){
            try {
                userService.updatePassword(user.getName(),new1);
                map.put("isUpdate", true);
            } catch (Exception e) {
                e.printStackTrace();
                map.put("isUpdate", false);
            }
        }
       return map;
    }

}
